package com.bawei.module_inspection

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseActivity
import com.bawei.module_inspection.databinding.ActivityInspectionDetailBinding
import com.bawei.module_inspection.fl.adapter.InspectionViewPageAdapter
import com.bawei.module_inspection.ui.InspectionViewModel
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@AndroidEntryPoint
@Route(path = Router.Ui.InspectionDetailActivity)
class InspectionDetailActivity : BaseActivity<InspectionViewModel, ActivityInspectionDetailBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_inspection_detail
    override val mViewModel: InspectionViewModel by viewModels()
    private val adapter by lazy { InspectionViewPageAdapter(supportFragmentManager,lifecycle) }
    @Autowired(name = "id", required = false)
    @JvmField
    var id: Int = 0
    @Autowired(name = "pointName", required = false)
    @JvmField
    var pointName: String? = null
    @Autowired(name = "pointLocation", required = false)
    @JvmField
    var pointLocation: String? = null
    @Autowired(name = "pointStatus", required = false)
    @JvmField
    var pointStatus: String? = null

    override fun initView() {
        mBinding.view2.adapter = adapter
        TabLayoutMediator(mBinding.tabLayout, mBinding.view2) { tab, position ->
            when (position) {
                0 -> tab.text = "巡检标准"
                1 -> tab.text = "巡检记录"
                2 -> tab.text = "工单记录"
                else -> ""
            }
        }.attach()
        // 直接从 Intent 获取参数（推荐）
    }

    override fun initListener() {
        mViewModel.getInspectionDetail(id)
    }

    override fun initData() {
        lifecycleScope.launch {
            mViewModel.mInspectionState.collect{
                mBinding.inspectionDetailName.text = pointName
                mBinding.inspectionDetailText.text = pointStatus
                mBinding.inspectionDetailHu.text = pointLocation
            }
        }
    }
}









